<@override name="content">
  <#if msg??>
  <div class="row">
    <div class="span5 offset4">
      <div class="alert alert-error">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <h4>Error!</h4>
      ${msg!}
      </div>
    </div>
  </div>
  </#if>
<div id="signup-box" class="row">
  <div class="span5 offset3">
    <form class="form-horizontal" id="signupForm" action="user/save" method="post">
      <div class="control-group">
        <div class="controls">
            <span class="help-block">Already have an account? <a href="login">Login here</a>
            </span>
        </div>
      </div>
      <div class="control-group <#if nameMsg??>error</#if>">
        <label class="control-label" for="inputAccount">Account</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="icon-user"></i></span>
            <input type="text" minlength="5" maxlength="15" id="inputAccount" name="User.name" value="${(User.name)!}"
                   placeholder="User name" autofocus required>
          </div>
          <p class="text-error" id="name-error">${nameMsg!}</p>
        </div>
      </div>
      <div class="control-group <#if nickMsg??>error</#if>">
        <label class="control-label" for="inputNick">Nick</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="oj-icon oj-icon-user-suit"></i></span>
            <input type="text" minlength="1" maxlength="255" id="inputNick" name="User.nick" value="${(User.nick)!}"
                   placeholder="Nick" autofocus required>
          </div>
          <p class="text-error" id="nick-error">${nickMsg!}</p>
        </div>
      </div>
      <div class="control-group <#if emailMsg??>error</#if>">
        <label class="control-label" for="inputEmail">Email</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="icon-envelope"></i></span>
            <input type="email" id="inputEmail" name="User.email" value="${(User.email)!}" placeholder="Email" required>
          </div>
          <p class="text-error" id="email-error">${emailMsg!}</p>
        </div>
      </div>
      <div class="control-group <#if passwordMsg??>error</#if>">
        <label class="control-label" for="inputPassword">Password</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="icon-lock"></i></span>
            <input type="password" minlength="6" maxlength="20" id="inputPassword" name="User.password"
                   placeholder="Password" required>
          </div>
          <p class="text-error">${passwordMsg!}</p>
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="inputConfirmPass">Confirm Password</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="icon-lock icon-white"></i></span>
            <input type="password" minlength="6" maxlength="20" id="inputConfirmPass" name="repass"
                   placeholder="Confirm your Password" required>
          </div>
          <p class="text-error">${confirmMsg!}</p>
        </div>
      </div>
      <div class="control-group <#if captchaMsg??>error</#if>">
        <label class="control-label" for="inputCaptcha">Captcha</label>
        <div class="controls">
          <div class="input-prepend">
            <span class="add-on"><i class="icon-check"></i></span>
            <input type="text" minlength="4" maxlength="4" id="inputCaptcha" class="input-small" name="captcha"
                   required>
          </div>
          <span id="captcha_span">
            <a id="captcha_id" onclick="getCaptcha();" href="javascript:;" title="click to change another one">
              <img id="captcha_img" src="captcha"/>
            </a>
          </span>
          <p class="text-error">${captchaMsg!}</p>
        </div>
      </div>
      <div class="control-group">
        <div class="controls">
          <input type="submit" class="btn btn-success" value="Signup">
        </div>
      </div>
    </form>
  </div>
</div>
</@override>

<@override name="scripts">
<script src='assets/jquery-validation/dist/jquery.validate.min.js' type='text/javascript'></script>
<script type="text/javascript">
  $().ready(function () {
    $("#signupForm").validate();
    $('#inputAccount').focusout(function () {
      var name = $('#inputAccount').val();
      if (name) {
        $.get('/api/user/isUserNameExist', { 'name': name }, function (data) {
          if (data.result) {
            $('#name-error').text('This user name already registered!');
            $('#name-error').parent().parent().addClass('error');
          } else {
            $('#name-error').text('');
            $('#name-error').parent().parent().removeClass('error');
          }
        });
      }
    });
    $('#inputEmail').focusout(function () {
      var email = $('#inputEmail').val();
      if (email) {
        $.get('/api/user/isEmailExist', { 'email': email }, function (data) {
          if (data.result) {
            $('#email-error').text('This Email already registered!');
          } else {
            $('#email-error').text('');
            $('#email-error').parent().parent().removeClass('error');
            $('#email-error').parent().parent().addClass('error');
          }
        });
      }
    });
  });
</script>
</@override>
<@extends name="../common/_layout.html" />
